<template>
  <div id="positionManagement">
    <el-row>
      <el-col :span="4">
        <div class="div_border_title">
          <h2>岗位信息管理</h2>
        </div>
      </el-col>
    </el-row>
    <div class="search-box">
      <SearchMenu :authority="3" @returnData="doSearch"></SearchMenu>
    </div>
    <div class="toolbar-box">
      <el-button-group>
        <el-button v-for="(toolbar,index) in toolbarList" :key="index" :type="toolbar.type" :icon="toolbar.icon"
                   @click="getButtonType(toolbar.event)">{{toolbar.name}}
        </el-button>
      </el-button-group>
    </div>
    <el-table :data="companyList" border highlight-current-row fit @row-click="clickRow"
              @current-change="handleTableChange" @row-dblclick="openDialog">
      <el-table-column type="index" :label="$t('index')" width="100" align="center"></el-table-column>
      <el-table-column prop="job_title" label="岗位名称" align="center"></el-table-column>
      <el-table-column prop="academic_requirements" :formatter="formatterendEdu" label="学历要求" width="150"
                       align="center"></el-table-column>
      <el-table-column prop="work_space" label="工作地点" align="center"></el-table-column>
      <el-table-column prop="company_name" label="公司姓名" align="center"></el-table-column>
    </el-table>
    <el-pagination v-if="total > 5" @current-change="handleCurrentChange" layout="total, prev, pager, next"
                   :total="total" :page-size="10" class="table-page-style"></el-pagination>
    <el-dialog title="编辑岗位信息" v-model="isDialog">
      <div class="dialog-content">
        <PositionManagementDialog :id="currentID" :type="type" @returnBack="getDialogState"></PositionManagementDialog>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import { commonNotify } from '../../assets/js/common.js'
  import { getStaticMapList } from '../../assets/js/GlobeDefine.js'
  import PositionManagementDialog from '@/components/positionManagement/PositionManagementDialog'
  import { postDataToServer } from '../../assets/js/post.js'
  import { getToolBarList } from '../../assets/js/buildStructure/list.js'
  import SearchMenu from '../common/SearchMenu'

  export default {
    name: 'positionManagement',
    data () {
      return {
        companyList: [],
        toolbarList: [],
        currentID: '',
        currData: '',
        page_no: 1,
        total: 0,
        isDialog: false,
        type: '',
        authority: 6
      }
    },
    created () {
      this.getToolBars()
      this.getCompanyDataList(1)
    },
    methods: {
      clickRow (row, event, column) {
        this.currentID = row.id
        this.currData = row
      },
      handleTableChange (currentRow, oldCurrentRow) {
        this.currData = currentRow
      },
      handleCurrentChange (pageNum) {
        this.page_no = pageNum
      },
      //双击打开dialog
      openDialog (row, event) {
        this.currData = row
        this.currentID = row.id
        this.isDialog = true
      },
      getCompanyDataList (pageNum) {
        let _this = this
        let parameter = new Object()
        parameter.page_no = pageNum
        parameter.page_size = 10
        postDataToServer('HM_RESUME_JOBS_LIST', parameter).then((data) => {
          if (data.status === 0) {
            _this.companyList = data.data_list
            _this.total = data.total_results
          }
        })
      },
      doSearch (params, pageNum) {
        let _this = this
        let parameter = new Object()
        parameter = params
        parameter.page_no = 1
        parameter.page_size = 10
        postDataToServer('HM_RESUME_JOBS_LIST', parameter).then((data) => {
          if (data.status === 0) {
            _this.companyList = data.data_list
            _this.total = data.total_results
          }
        })
      },
      //取得功能按钮
      getToolBars () {
        this.toolbarList = getToolBarList('list', this.authority)
      },
      //根据不同的按钮执行不同的操作
      getButtonType (type) {
        let _this = this
        switch (type) {
          case 'edit':
            _this.edit(_this.currData)
            break
          case 'delete':
            _this.delete()
          default:
            break
        }
      },
      //编辑按钮
      edit (row) {
        if (row.id === '' || row.id === undefined) {
          this.$message({
            message: '请选中一行',
            type: 'warning'
          })
        } else {
          this.openDialog(row, '')
        }
      },
      //删除按钮
      delete () {
        let _this = this
        if (_this.currentID !== '') {
          _this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            let param = new Object()
            param.id = _this.currentID
            postDataToServer('HM_COMPANY_INTERVIEW_DEL', param)
              .then(function (res) {
                (_this, res.status, 'DEL')
                _this.getCompanyDataList(_this.page_no)
              })
          }).catch(() => {
            _this.$message({
              type: 'info',
              message: '已取消删除'
            })
          })
        } else {
          this.$message({
            message: '请选中一行',
            type: 'warning'
          })
        }
      },
      //接受子组件的状态关闭子组件
      getDialogState (state) {
        this.currData = {}
        this.isDialog = state
      },
      formatterendEdu (row) {
        return getStaticMapList('education', row.academic_requirements)
      },
    },
    components: {
      SearchMenu,
      PositionManagementDialog
    },
    watch: {
      page_no (val, oldVal) {
        this.getCompanyDataList(val)
      }
    }
  }
</script>

<style scoped>
  #positionManagement {
    padding: 2em;
  }

  .toolbar-box {
    border: 1px solid #20A0FF;
    background-color: #20A0FF;
    margin-top: 20px;
  }

  /*弹出框样式*/
  .el-dialog {
    background-color: black;
  }
</style>
